package com.laboratory.manage.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laboratory.manage.dao.CarouselDao;
import com.laboratory.manage.entity.CarouselEntity;
import com.laboratory.manage.service.CarouselService;
import com.laboratory.manage.utils.PageUtils;
import com.laboratory.manage.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: qinaolong
 * @Date: 2023/05/22/10:07
 * @Description:
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselDao, CarouselEntity> implements CarouselService {

    @Autowired
    private CarouselDao carouselDao;

    @Override
    public List<CarouselEntity> allList() {
        QueryWrapper<CarouselEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
        return carouselDao.selectList(queryWrapper);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CarouselEntity> page = this.page(new Query<CarouselEntity>().getPage(params),
                new QueryWrapper<CarouselEntity>().eq("is_delete", 0)
        );
        return new PageUtils(page);
    }

    @Override
    public boolean update(CarouselEntity carouselEntity) {

        int i = carouselDao.updateById(carouselEntity);
        if(i != 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(List<Long> asList) {
        for (Long id : asList) {
            CarouselEntity carouselEntity = carouselDao.selectById(id);
            carouselEntity.setIsDelete("1");
            int i = carouselDao.updateById(carouselEntity);
            if(i == 0){
                return false;
            }
        }
        return true;
    }
}
